﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;



public partial class admin_to_rent : System.Web.UI.Page
{
    DataTable table = new DataTable("Customers");
    string p_id = null;
    string c_id;
    string t_id;
    private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
    {
        byte[] Ret;
        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageToConvert.Save(ms, formatOfImage);
                Ret = ms.ToArray();
            }
        }
        catch (Exception) { throw; }
        return Ret;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["p_id"] == null)
        {
            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random = new Random();
            var p_id = new string(
                Enumerable.Repeat(chars, 8)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());




            //Session["p_id"] = p_id;
            SqlConnection con = null;

            con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            con.Open();


            SqlCommand cmd1 = new SqlCommand("SELECT p_id FROM properties_rent where p_id='" + p_id + "'", con);

            SqlDataReader dr2 = cmd1.ExecuteReader();


            if (dr2.Read())
            {
                var chars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random1 = new Random();
                var n_id = new string(
                    Enumerable.Repeat(chars1, 8)
                              .Select(s => s[random1.Next(s.Length)])
                              .ToArray());


                Request.QueryString["p_id"] = n_id;

            }






            else
            {
                Session["p_id"]= p_id;

            }
            dr2.Close();
            con.Close();





        }

        else
        {
            p_id = Session["p_id"].ToString();
        }











        if (Session["t_id"] == null)
        {
            var chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random2 = new Random();
            var t_id = new string(
                Enumerable.Repeat(chars2, 8)
                          .Select(s => s[random2.Next(s.Length)])
                          .ToArray());

            Session["t_id"] = t_id;
        }

        else
        {
            t_id = Session["t_id"].ToString();
        }
        //Session["myTable"] = table;

        //if (IsPostBack == true)
       
            table.Columns.Add("action_");
            table.Columns.Add("p_id");
            table.Columns.Add("t_id");
            table.Columns.Add("deal_status");
            table.Columns.Add("created");
            table.Columns.Add("update_");
            table.Columns.Add("min_");
            table.Columns.Add("hrs");
       
            table.Columns.Add("fast_reminder");
            table.Columns.Add("day_");
            table.Columns.Add("agent");
            table.Columns.Add("sec_agent");
            table.Columns.Add("min1");    
        table.Columns.Add("hr");
     
          
            table.Columns.Add("rank");
            table.Columns.Add("commission");
        
          
            table.Columns.Add("sig");
            table.Columns.Add("refer");
            table.Columns.Add("cust_rank");
            table.Columns.Add("cust_refer");
            table.Columns.Add("comment");
            table.Columns.Add("terms");
            table.Columns.Add("to_do");
           
           
            table.Columns.Add("cus_to_do");
           
            table.Columns.Add("status_");
         
            table.Columns.Add("full_day");
            table.Columns.Add("to_do_msg");
            table.Columns.Add("to_do_date");
           
            table.Columns.Add("to_min");
            table.Columns.Add("to_hr");
            table.Columns.Add("added_by");
            table.Columns.Add("cus_deal_status");
            table.Columns.Add("cust_stat");
            table.Columns.Add("cust_reminder");

           
            

        


        if (Session["myTable"] == null)
        {
            Session["myTable"] = table;
        }

        else
        {


            table = Session["myTable"] as DataTable;

        }


        table = Session["myTable"] as DataTable;


        //TextBox16.Text = "0";

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        // Label1.Text = Session["email"].ToString();
        // txtcreate.Text = System.DateTime.Now.ToString();
        txtagent.Text = Session["email"].ToString();



    }
    protected void DropDownList5_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        //Session["type"] = DropDownList5.SelectedValue;
        //Session["proptype"] = DropDownList6.SelectedValue;


    }

    protected void ok(object sender, System.EventArgs e)
    {


        if (Session["t_id"] == null)
        {
            //Random r1 = new Random();
            //int num = r1.Next(0, 99999999); // generate random number
            //string number = string.Format("{0:D8}", num);

            //Random r2 = new Random();
            //int num2 = r2.Next(0, 26); // generate random letter
            //char letter = (char)('A' + num2);

            var chars3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random3 = new Random();
            var t_id = new string(
                Enumerable.Repeat(chars3, 8)
                          .Select(s => s[random3.Next(s.Length)])
                          .ToArray());
            //t_id = letter + number;
            Session["t_id"] = t_id;
        }

        else
        {
            t_id = Session["t_id"].ToString();
        }
        try
        {

            table.Rows.Add(p_id, p_id, t_id, DropDownList4.SelectedValue, txtdate.Text, txtupdate.Text, ddlmint.SelectedValue, ddlhr.SelectedValue,  DropDownList52.SelectedValue, txtFR.Text, txtagent.Text, DropDownList6.SelectedValue, ddlmint0.SelectedValue, ddlhr0.SelectedValue, DropDownList53.SelectedValue, txtcommsin.Text, DropDownList54.SelectedValue, DropDownList55.SelectedValue, TextBox55.Text, TextBox56.Text, txtcomment.Text, txtterms.Text, DropDownList28.SelectedValue, DropDownList29.SelectedValue,  DropDownList30.SelectedValue, txtdo.Text, txtmsg.Text, txttododate.Text, ddlmint1.SelectedValue, ddlhr1.SelectedValue, "Admin",TextBox53.Text, TextBox78.Text, TextBox54.Text);
        }

        catch (Exception err)
        {
            Label2.Text = err.Message;

        }


        GridView1.DataSource = table;
        GridView1.DataBind();
        Session["myTable"] = table;

        string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
        if (!Directory.Exists(path1))
        {
            Directory.CreateDirectory(path1);
        }

        if (FileUpload2.HasFile)
        {

            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {

                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hpf.FileName)));

                    SqlConnection co = null;
                    co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                    co.Open();

                    SqlCommand cmd = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);
                    //id nvarchar (50),
                    //FileName nvarchar (50),
                    //FilePath nvarchar (50)


                    cmd.Parameters.AddWithValue("@id", Session["p_id"]);
                    cmd.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                    cmd.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hpf.FileName));


                    cmd.ExecuteNonQuery();
                    co.Close();


                }
            }
        }

        DropDownList4.SelectedIndex = 0;

        DropDownList8.SelectedIndex = 0;
        txtdate.Text = "";
        txtupdate.Text = "";
        ddlhr.SelectedIndex = 0;
        ddlmint1.SelectedIndex = 0;
        DropDownList57.SelectedIndex = 0;
        txtFR.Text = "";
        ddlhr0.SelectedIndex = 0;
        ddlmint0.SelectedIndex = 0;
        DropDownList54.SelectedIndex = 0;
        txtcommsin.Text = "";
        DropDownList54.SelectedIndex = 0;
        DropDownList55.SelectedIndex = 0;
        TextBox56.Text = "";
        txtcomment.Text = "";
        txtterms.Text = "";
        DropDownList28.SelectedIndex = 0;

        DropDownList29.SelectedIndex = 0;
        DropDownList30.SelectedIndex = 0;
        txtmsg.Text = "";
        txttododate.Text = "";
        ddlhr1.SelectedIndex = 0;
        ddlmint1.SelectedIndex = 0;
        ddlmint.SelectedIndex = 0;
        DropDownList56.SelectedIndex = 0;
        DropDownList6.SelectedIndex = 0;






        /////////////////////Add My Mrinal/////////////

        //Session.Clear();
        //Session.Abandon();
        //Session.RemoveAll();

        //Session.Contents.RemoveAll();

        //GridView1.Columns.Clear();

        //Session["myTable"] = null;

        //table.Clear();

        //GridView1.DataSource = null;
        //GridView1.DataBind();

////////////////////////////////////////////////////////////////////////
    }


    public void properties()
    {
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();

        var chars4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        var random4 = new Random();
        var p_id = new string(
            Enumerable.Repeat(chars4, 8)
                      .Select(s => s[random4.Next(s.Length)])
                      .ToArray());
        //Random r1 = new Random();
        //int num = r1.Next(0, 99999999); // generate random number
        //string number = string.Format("{0:D8}", num);

        //Random r2 = new Random();
        //int num2 = r2.Next(0, 26); // generate random letter
        //char letter = (char)('A' + num2);


        //p_id = letter + number;

        SqlCommand cmd = new SqlCommand("Insert into properties_rent values(@frontend,@c_type,@cust_ctype, @agent_name,@type, @p_id, @fname, @lname, @email,  @phone, @street,@houseno,@nghr, @city,@country,@zip,@cust_proptype,@custom_proptype,@prop_cond,@cust_prop_cond,@nghr1,@f_city,@f_country,@f_zip,@f_street,@h_no,@apartment_no,@room,@floor_no,@total_floor,@buil_cond,@cust_cond,@no_resi,@to_floor_no,@age_of_building,@no_of_residence,@parking, @custom_park, @furniture,@custom_furniture,@toilet,@custom_toilet,@shower,@custom_shower,@kitchen,@custom_kitchen,@ground,@custom_ground,@roof,@view_prop,@custom_view,@front_rear_view,@custom_front_rear,@garden,@custom_garden, @evacuation_date,@custome_evacuation_date,@land,@custom_land,@area,@custom_area,@arnona,@p_basement,@cust_basement,@p_strong,@cust_strong, @p_ac, @cust_ac, @p_balconies, @p_balcony_area,@p_balcony_size,@p_balconies1,@p_balcony_area1,@p_balcony_size1,@balconies_num, @p_maintance,@p_building,@cust_building,@p_boiler,@cust_boiler,@animals,@cust_animals,@roommates,@cust_roommates,@entering_date,@elevator,@cust_elevator,@permises,@prop_size,@sign_size,@p_tax,  @r_est, @a_hours, @guarntee, @cust_guarntee, @voucher, @cust_vouc,@smoke,@cust_smoke,@price,@price_type, @old_price, @old_price_type, @p_north, @p_south, @p_east, @p_west, @p_smart,@p_alarm,@p_bars,@p_handi, @p_teather,@p_gym,@p_zacuji,@p_pool,@custom,@custom_ch,@comments,@status1,@rent_status,@adding_date,@adding_by,@price_dur,@wcdrop1,@wccust1,@wcdrop2,@wccust2,@wcdrop3,@wccust3,@wcdrop4,@wccust4,@shwrdrop1,@shwrcust1,@shwrdrop2,@shwrcust2,@shwrdrop3,@shwrcust3,@balcdrop1,@balcsize1,@balcontext1,@balconcust1,@balcdrop2,@balcsize2,@balcontext2,@balconcust2,@balcdrop3,@balcsize3,@balcontext3,@balconcust3,@nghrnew,@countrynw,@St,@city3,@cat_home,@countyr,@apart,@bathrooms5,@cus_bathrooms,@balcon_cust3,@balcon_cust4, @add_date)", conn);

        cmd.Parameters.AddWithValue("@frontend", DropDownList32.SelectedValue);
        cmd.Parameters.AddWithValue("@c_type", DropDownList1.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_ctype", TextBox20.Text);
        cmd.Parameters.AddWithValue("@agent_name ", DropDownList31.SelectedValue);
        cmd.Parameters.AddWithValue("@type", "To Rent");
        cmd.Parameters.AddWithValue("@p_id", Session["p_id"]);
        cmd.Parameters.AddWithValue("@fname", txtfname1.Text);
        cmd.Parameters.AddWithValue("@lname", txtlname1.Text);
        cmd.Parameters.AddWithValue("@email", TextBox22.Text);
        cmd.Parameters.AddWithValue("@phone", TextBox21.Text);
        cmd.Parameters.AddWithValue("@street", txthno.Text);
        cmd.Parameters.AddWithValue("@houseno", txtcity.Text);
        cmd.Parameters.AddWithValue("@nghr", TextBox3.Text);
        cmd.Parameters.AddWithValue("@city", txtssn.Text);
        cmd.Parameters.AddWithValue("@country", txtzip.Text);
        cmd.Parameters.AddWithValue("@zip", TextBox23.Text);
        cmd.Parameters.AddWithValue("@cust_proptype", DropDownList5.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_proptype", TextBox4.Text);
        cmd.Parameters.AddWithValue("@prop_cond", DropDownList8.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_prop_cond", TextBox5.Text);
        cmd.Parameters.AddWithValue("@nghr1", TextBox35.Text);
        cmd.Parameters.AddWithValue("@f_city", TextBox28.Text);
        cmd.Parameters.AddWithValue("@f_country", txtpfcountry.Text);
        cmd.Parameters.AddWithValue("@f_zip", TextBox29.Text);
        cmd.Parameters.AddWithValue("@f_street", TextBox50.Text);
        cmd.Parameters.AddWithValue("@h_no", TextBox13.Text);
        cmd.Parameters.AddWithValue("@apartment_no", TextBox14.Text);
        cmd.Parameters.AddWithValue("@room", txtRoom.Text);
        cmd.Parameters.AddWithValue("@floor_no", TextBox25.Text);
        cmd.Parameters.AddWithValue("@total_floor", TextBox26.Text);
        cmd.Parameters.AddWithValue("@buil_cond", DropDownList44.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_cond", TextBox15.Text);
        cmd.Parameters.AddWithValue("@age_of_building", TextBox51.Text);
        cmd.Parameters.AddWithValue("@no_of_residence", TextBox27.Text);
        cmd.Parameters.AddWithValue("@parking", ddlparking.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_park", txtpark.Text);
        cmd.Parameters.AddWithValue("@furniture", DropDownList18.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_furniture", txtfurniture.Text);
        cmd.Parameters.AddWithValue("@toilet", DropDownList19.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_toilet", txttoilets.Text);
        cmd.Parameters.AddWithValue("@shower", DropDownList20.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_shower", TextBox16.Text);
        cmd.Parameters.AddWithValue("@kitchen", ddlkitchen.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_kitchen", txtkitchen.Text);
        cmd.Parameters.AddWithValue("@ground", ddlground.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_ground", txtground.Text);
        cmd.Parameters.AddWithValue("@roof", TextBox52.Text);
        cmd.Parameters.AddWithValue("@view_prop", DropDownList11.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_view", TextBox8.Text);
        cmd.Parameters.AddWithValue("@front_rear_view", DropDownList16.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_front_rear", TextBox11.Text);
        cmd.Parameters.AddWithValue("@garden", ddlgarden.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_garden", txtgarden.Text);
        cmd.Parameters.AddWithValue("@evacuation_date", DropDownList12.SelectedValue);
        cmd.Parameters.AddWithValue("@custome_evacuation_date", TextBox7.Text);
        cmd.Parameters.AddWithValue("@land", DropDownList59.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_land", TextBox10.Text);
        cmd.Parameters.AddWithValue("@area", DropDownList58.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_area", TextBox17.Text);
        cmd.Parameters.AddWithValue("@arnona", TextBox40.Text);
        cmd.Parameters.AddWithValue("@p_basement", txtBasement.Text);
        cmd.Parameters.AddWithValue("@cust_basement", txtbasetxt.Text);
        cmd.Parameters.AddWithValue("@p_strong", txtStrong.Text);
        cmd.Parameters.AddWithValue("@cust_strong", txtstrongtxt.Text);
        cmd.Parameters.AddWithValue("@p_ac", txtAC.Text);
        cmd.Parameters.AddWithValue("@cust_ac", txtactxt.Text);
        cmd.Parameters.AddWithValue("@p_balconies", txtBalconies.Text);
        cmd.Parameters.AddWithValue("@p_balcony_area", TextBox6.Text);
        cmd.Parameters.AddWithValue("@p_balcony_size", DropDownList41.SelectedValue);
        cmd.Parameters.AddWithValue("@p_balconies1", txtBalconies0.Text);
        cmd.Parameters.AddWithValue("@p_balcony_area1", TextBox38.Text);
        cmd.Parameters.AddWithValue("@p_balcony_size1", DropDownList42.SelectedValue);
        //cmd.Parameters.AddWithValue("@balconies_num", DropDownList42.SelectedValue);
        cmd.Parameters.AddWithValue("@p_maintance", TextBox9.Text);
        cmd.Parameters.AddWithValue("@p_building", ddlbuiding.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_building", txtbuilding.Text);
        cmd.Parameters.AddWithValue("@p_boiler", ddlboiler.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_boiler", txtboiler.Text);
        cmd.Parameters.AddWithValue("@animals", ddlanimals.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_animals", txtanimals.Text);
        cmd.Parameters.AddWithValue("@roommates", ddlroommates.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_roommates", txtroomates.Text);
        cmd.Parameters.AddWithValue("@entering_date", TextBox37.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList50.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_elevator", TextBox19.Text);
        cmd.Parameters.AddWithValue("@permises", txtProperty.Text);
        cmd.Parameters.AddWithValue("@prop_size", txtpsize.Text);
        cmd.Parameters.AddWithValue("@sign_size", ddlpsize.SelectedValue);
        cmd.Parameters.AddWithValue("@p_tax", TextBox31.Text);
        cmd.Parameters.AddWithValue("@r_est", TextBox32.Text);
        cmd.Parameters.AddWithValue("@a_hours", TextBox33.Text);
        cmd.Parameters.AddWithValue("@guarntee", ddlgrnte.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_guarntee", txtgrnte.Text);
        cmd.Parameters.AddWithValue("@voucher", ddlvou.Text);
        cmd.Parameters.AddWithValue("@cust_vouc", txtvou.Text);
        cmd.Parameters.AddWithValue("@smoke", ddlsmoke.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_smoke", txtsmoke.Text);
        cmd.Parameters.AddWithValue("@price", txtPrice.Text);
        cmd.Parameters.AddWithValue("@price_type", DropDownList33.SelectedValue);
        cmd.Parameters.AddWithValue("@old_price", txtOldPrice.Text);
        cmd.Parameters.AddWithValue("@old_price_type", DropDownList51.SelectedValue);
        cmd.Parameters.AddWithValue("@p_north", CheckBox9.Checked);
        cmd.Parameters.AddWithValue("@p_south", CheckBox10.Checked);
        cmd.Parameters.AddWithValue("@p_east", CheckBox11.Checked);
        cmd.Parameters.AddWithValue("@p_west", CheckBox12.Checked);
        cmd.Parameters.AddWithValue("@p_smart", CheckBox1.Checked);
        cmd.Parameters.AddWithValue("@p_alarm", CheckBox2.Checked);
        cmd.Parameters.AddWithValue("@p_bars", CheckBox3.Checked);
        cmd.Parameters.AddWithValue("@p_handi", CheckBox4.Checked);
        cmd.Parameters.AddWithValue("@p_teather", CheckBox5.Checked);
        cmd.Parameters.AddWithValue("@p_gym", CheckBox6.Checked);
        cmd.Parameters.AddWithValue("@p_zacuji", CheckBox7.Checked);
        cmd.Parameters.AddWithValue("@p_pool", CheckBox8.Checked);
        cmd.Parameters.AddWithValue("@custom", CheckBox13.Checked);
        cmd.Parameters.AddWithValue("@custom_ch", TextBox24.Text);
        cmd.Parameters.AddWithValue("@comments", TextBox68.Text);
        cmd.Parameters.AddWithValue("@status1", "1");
        cmd.Parameters.AddWithValue("@rent_status", "0");
        cmd.Parameters.AddWithValue("@adding_date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@adding_by", "admin");
        cmd.Parameters.AddWithValue("@price_dur", DropDownList2.SelectedValue);
        cmd.Parameters.AddWithValue("@wcdrop1", DropDownList56.SelectedValue);
        cmd.Parameters.AddWithValue("@wccust1", TextBox60.Text);
        cmd.Parameters.AddWithValue("@wcdrop2", DropDownList63.SelectedValue);
        cmd.Parameters.AddWithValue("@wccust2", TextBox61.Text);
        cmd.Parameters.AddWithValue("@wcdrop3", DropDownList64.SelectedValue);
        cmd.Parameters.AddWithValue("@wccust3", TextBox62.Text);
        cmd.Parameters.AddWithValue("@wcdrop4", DropDownList65.SelectedValue);
        cmd.Parameters.AddWithValue("@wccust4", TextBox63.Text);
        cmd.Parameters.AddWithValue("@shwrdrop1", DropDownList57.SelectedValue);
        cmd.Parameters.AddWithValue("@shwrcust1", TextBox64.Text);
        cmd.Parameters.AddWithValue("@shwrdrop2", DropDownList66.SelectedValue);
        cmd.Parameters.AddWithValue("@shwrcust2", TextBox65.Text);
        cmd.Parameters.AddWithValue("@shwrdrop3", DropDownList67.SelectedValue);
        cmd.Parameters.AddWithValue("@shwrcust3", TextBox66.Text);
        cmd.Parameters.AddWithValue("@bathrooms5", DropDownList68.SelectedValue);
        cmd.Parameters.AddWithValue("@cus_bathrooms", TextBox67.Text);
        cmd.Parameters.AddWithValue("@balcdrop1", txtBalconies1.SelectedValue);
        cmd.Parameters.AddWithValue("@balcontext1", DropDownList60.SelectedValue);
        cmd.Parameters.AddWithValue("@balconcust1", TextBox73.Text);
        cmd.Parameters.AddWithValue("@balcdrop2", txtBalconies2.SelectedValue);
        cmd.Parameters.AddWithValue("@balcsize2", TextBox58.Text);
        cmd.Parameters.AddWithValue("@balcontext2", DropDownList61.SelectedValue);
        cmd.Parameters.AddWithValue("@balconcust2", TextBox74.Text);
        cmd.Parameters.AddWithValue("@balcon_cust3", TextBox75.Text);
        cmd.Parameters.AddWithValue("@balcon_cust4", TextBox76.Text);
        cmd.Parameters.AddWithValue("@balcdrop3", txtBalconies3.SelectedValue);
        cmd.Parameters.AddWithValue("@balcsize3", TextBox59.Text);
        cmd.Parameters.AddWithValue("@balcontext3", DropDownList62.SelectedValue);
        cmd.Parameters.AddWithValue("@balconcust3", TextBox77.Text);
        cmd.Parameters.AddWithValue("@nghrnew", TextBox69.Text);
        cmd.Parameters.AddWithValue("@countrynw", TextBox72.Text);
        // cmd.Parameters.AddWithValue("@St", TextBox50.Text);
        cmd.Parameters.AddWithValue("@city3", TextBox70.Text);
        // cmd.Parameters.AddWithValue("@cat_home", TextBox13.Text);
        cmd.Parameters.AddWithValue("@countyr", TextBox57.Text);
        cmd.Parameters.AddWithValue("@countyr2", TextBox71.Text);
        // cmd.Parameters.AddWithValue("@apart", TextBox14.Text);
        cmd.Parameters.AddWithValue("@add_date", TextBox79.Text);


        ////////Blank////////////
        cmd.Parameters.AddWithValue("@no_resi", TextBox80.Text);
        cmd.Parameters.AddWithValue("@to_floor_no", TextBox81.Text);
        cmd.Parameters.AddWithValue("@balconies_num", TextBox82.Text);
        cmd.Parameters.AddWithValue("@balcsize1", TextBox83.Text);
        cmd.Parameters.AddWithValue("@St", TextBox84.Text);
        cmd.Parameters.AddWithValue("@cat_home", TextBox85.Text);
        cmd.Parameters.AddWithValue("@apart", TextBox86.Text);
        cmd.ExecuteNonQuery();

        conn.Close();

    }


    public void task()
    {
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();

        SqlCommand cmd3 = new SqlCommand("insert into task (action_,p_id,t_id,deal_status,created,update_,hrs,min_,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@action_,@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
        cmd3.Parameters.AddWithValue("@action_","0");
        cmd3.Parameters.AddWithValue("@p_id ", Session["p_id"]);
        cmd3.Parameters.AddWithValue("@t_id ", Session["t_id"]);
        cmd3.Parameters.AddWithValue("@deal_status ", DropDownList4.SelectedValue);
        cmd3.Parameters.AddWithValue("@created ", txtdate.Text);
        cmd3.Parameters.AddWithValue("@update_ ", txtupdate.Text);
        cmd3.Parameters.AddWithValue("@hrs", ddlhr.SelectedValue);
        cmd3.Parameters.AddWithValue("@min_", ddlmint.SelectedValue);

        cmd3.Parameters.AddWithValue("@fast_reminder", DropDownList52.SelectedValue);
        cmd3.Parameters.AddWithValue("@day_ ", txtFR.Text);
        cmd3.Parameters.AddWithValue("@hr", ddlhr0.SelectedValue);
        cmd3.Parameters.AddWithValue("@min1", ddlmint0.SelectedValue);
        cmd3.Parameters.AddWithValue("@agent", txtagent.Text);
        cmd3.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
        cmd3.Parameters.AddWithValue("@rank", DropDownList53.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_rank", TextBox55.Text);
        cmd3.Parameters.AddWithValue("@commission", txtcommsin.Text);
        cmd3.Parameters.AddWithValue("@sig", DropDownList54.SelectedValue);
        cmd3.Parameters.AddWithValue("@refer", DropDownList55.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_refer", TextBox56.Text);
        cmd3.Parameters.AddWithValue("@comment", txtcomment.Text);
        cmd3.Parameters.AddWithValue("@terms", txtterms.Text);
        cmd3.Parameters.AddWithValue("@to_do", DropDownList28.SelectedValue);
        cmd3.Parameters.AddWithValue("@cus_to_do", txtdo.Text);
        cmd3.Parameters.AddWithValue("@status_ ", DropDownList29.SelectedValue);
        cmd3.Parameters.AddWithValue("@full_day", DropDownList30.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_do_msg", txtmsg.Text);
        cmd3.Parameters.AddWithValue("@to_do_date", txttododate.Text);
        cmd3.Parameters.AddWithValue("@to_hr", ddlhr1.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_min", ddlmint1.Text);

        cmd3.Parameters.AddWithValue("@added_by", Session["email"]);
        cmd3.Parameters.AddWithValue("@cus_deal_status", TextBox53.Text);
        cmd3.Parameters.AddWithValue("@cust_stat", TextBox78.Text);
        cmd3.Parameters.AddWithValue("@cust_reminder", TextBox54.Text);




        cmd3.ExecuteNonQuery();

        conn.Close();
    }






    public void fileupload1()
    {

        if (FileUpload1.HasFile)
        {
            string path = Server.MapPath("upload/" + Session["p_id"] + "/" + "Image");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);


                if (FileUpload1.HasFile)
                {

                    HttpFileCollection hfc = Request.Files;
                    for (int i = 0; i < hfc.Count; i++)
                    {

                        HttpPostedFile hpf = hfc[i];
                        if (hpf.ContentLength > 0)
                        {

                            hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Image/" + System.IO.Path.GetFileName(hpf.FileName)));


                            SqlConnection co = null;
                            co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                            co.Open();

                            SqlCommand cmd1 = new SqlCommand("Insert into images_torent values(@id,@FileName ,@FilePath,@f_end)", co);
                            //id nvarchar (50),
                            //FileName nvarchar (50),
                            //FilePath nvarchar (50)


                            cmd1.Parameters.AddWithValue("@id", Session["p_id"]);
                            cmd1.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                            cmd1.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/Image/" + hpf.FileName));
                            cmd1.Parameters.AddWithValue("@f_end", DropDownList32.SelectedValue);

                            cmd1.ExecuteNonQuery();
                            co.Close();
                        }
                    }
                }
            }
        }


    }



    public void fileupload2()
    {

        if (FileUpload2.HasFile)
        {

            string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
            if (!Directory.Exists(path1))
            {
                Directory.CreateDirectory(path1);
                HttpFileCollection hfd = Request.Files;
                for (int i = 0; i < hfd.Count; i++)
                {
                    HttpPostedFile hf = hfd[i];
                    if (hf.ContentLength > 0)
                    {
                        hf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hf.FileName)));

                        SqlConnection co = null;
                        co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                        co.Open();

                        SqlCommand cmd2 = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);



                        cmd2.Parameters.AddWithValue("@id", Session["p_id"]);
                        cmd2.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hf.FileName));
                        cmd2.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hf.FileName));


                        cmd2.ExecuteNonQuery();
                        co.Close();
                    }
                }
            }
        }


    }
    protected void Save_Click(object sender, System.EventArgs e)
    {






        if (table.Rows.Count < 1)
        {
            properties();

            fileupload1();
            fileupload2();

            task();

        }
        else
        {
            properties();

            fileupload1();
            fileupload2();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                string action_ = table.Rows[i]["action_"].ToString().Trim();
                string pid = table.Rows[i]["p_id"].ToString().Trim();
                string tid = table.Rows[i]["t_id"].ToString().Trim();
                string deal_status = table.Rows[i]["deal_status"].ToString().Trim();
                string created = table.Rows[i]["created"].ToString().Trim();
                string update_ = table.Rows[i]["update_"].ToString().Trim();
                string min_ = table.Rows[i]["min_"].ToString().Trim();
                string hrs = table.Rows[i]["hrs"].ToString().Trim();
                string fast_reminder = table.Rows[i]["fast_reminder"].ToString().Trim();
                string day_ = table.Rows[i]["day_"].ToString().Trim();
             
                string agent = table.Rows[i]["agent"].ToString().Trim();
                string sec_agent = table.Rows[i]["sec_agent"].ToString().Trim();
                string min1 = table.Rows[i]["min1"].ToString().Trim();
                string hr = table.Rows[i]["hr"].ToString().Trim();
                string rank = table.Rows[i]["rank"].ToString().Trim();
                string commission = table.Rows[i]["commission"].ToString().Trim();
               
                string sig = table.Rows[i]["sig"].ToString().Trim();
                string refer = table.Rows[i]["refer"].ToString().Trim();
                string cust_rank = table.Rows[i]["cust_rank"].ToString().Trim();
             
                string cust_refer = table.Rows[i]["cust_refer"].ToString().Trim();
                string comment = table.Rows[i]["comment"].ToString().Trim();
                string terms = table.Rows[i]["terms"].ToString().Trim();
                string to_do = table.Rows[i]["to_do"].ToString().Trim();
                string cus_to_do = table.Rows[i]["cus_to_do"].ToString().Trim();
                string status_ = table.Rows[i]["status_"].ToString().Trim();
                string full_day = table.Rows[i]["full_day"].ToString().Trim();
                string to_do_msg = table.Rows[i]["to_do_msg"].ToString().Trim();
                string to_do_date = table.Rows[i]["to_do_date"].ToString().Trim();
             
                string to_min = table.Rows[i]["to_min"].ToString().Trim();
                string to_hr = table.Rows[i]["to_hr"].ToString().Trim();
                string added_by = table.Rows[i]["added_by"].ToString().Trim();
             
                string cus_deal_status = table.Rows[i]["cus_deal_status"].ToString().Trim();

                string cust_stat = table.Rows[i]["cust_stat"].ToString().Trim();
                string cust_reminder = table.Rows[i]["cust_reminder"].ToString().Trim();
             
              

                
                SqlConnection conn = null;
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                conn.Open();

                SqlCommand cmd1 = new SqlCommand("insert into task (p_id,t_id,deal_status,created,update_,min_,hrs,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
                cmd1.Parameters.AddWithValue("@p_id ", pid);
                cmd1.Parameters.AddWithValue("@t_id ", t_id);
                cmd1.Parameters.AddWithValue("@deal_status ", deal_status);
                cmd1.Parameters.AddWithValue("@created ", created);
                cmd1.Parameters.AddWithValue("@update_ ", update_);
                cmd1.Parameters.AddWithValue("@min_", min_);
                cmd1.Parameters.AddWithValue("@hrs", hrs);
                cmd1.Parameters.AddWithValue("@fast_reminder", fast_reminder);
                cmd1.Parameters.AddWithValue("@day_ ", day_);
                cmd1.Parameters.AddWithValue("@hr", hr);
                cmd1.Parameters.AddWithValue("@min1", min1);
                cmd1.Parameters.AddWithValue("@agent", agent);
                cmd1.Parameters.AddWithValue("@sec_agent", sec_agent);
                cmd1.Parameters.AddWithValue("@rank", rank);
                cmd1.Parameters.AddWithValue("@cust_rank", cust_rank);
                cmd1.Parameters.AddWithValue("@commission", commission);
                cmd1.Parameters.AddWithValue("@sig", sig);
                cmd1.Parameters.AddWithValue("@refer", refer);
                cmd1.Parameters.AddWithValue("@cust_refer", cust_refer);
                cmd1.Parameters.AddWithValue("@comment", comment);
                cmd1.Parameters.AddWithValue("@terms", terms);
                cmd1.Parameters.AddWithValue("@to_do", to_do);
                cmd1.Parameters.AddWithValue("@cus_to_do", cus_to_do);
                cmd1.Parameters.AddWithValue("@status_ ", status_);
                cmd1.Parameters.AddWithValue("@full_day", full_day);
                cmd1.Parameters.AddWithValue("@to_do_msg", to_do_msg);
                cmd1.Parameters.AddWithValue("@to_do_date", to_do_date);
                cmd1.Parameters.AddWithValue("@to_hr", to_hr);
                cmd1.Parameters.AddWithValue("@to_min", to_min);

                cmd1.Parameters.AddWithValue("@added_by", Session["email"]);
                cmd1.Parameters.AddWithValue("@cus_deal_status", cus_deal_status);
                cmd1.Parameters.AddWithValue("@cust_stat", cust_stat);

                cmd1.Parameters.AddWithValue("@cust_reminder", cust_reminder);



                cmd1.ExecuteNonQuery();
                GridView1.Columns.Clear();

                table.Clear();

                conn.Close();
            }
















        }

        Session["p_id"] = null;
        Session.Clear();
        Session["myTable"] = null;
        Session.Remove("myTable");

        Session["Customers"] = null;
        Session.Remove("Customers");


        Session.Remove("p_id");
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();

        Session.Contents.RemoveAll();

        GridView1.Columns.Clear();

        table.Clear();

        GridView1.DataSource = null;
        GridView1.DataBind();

        Response.Cache.SetCacheability(HttpCacheability.NoCache); 
        Response.Redirect("property_add_confirmation.aspx");



    }










    protected void txtcreate_TextChanged(object sender, EventArgs e)
    {

    }
}







